package c.x.jy.admin.controller;

import c.x.jy.common.utils.PageUtils;
import c.x.jy.common.utils.R;
import c.x.jy.dao.entity.ClubEntity;
import c.x.jy.service.service.ClubService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 
 *
 * @author amwhyh
 * @email xxx@xx.com
 * @date 2021-07-12 10:30:08
 */
@RestController
@RequestMapping("cms/club")
public class ClubController extends AbstractController {
    @Autowired
    private ClubService clubService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("cms:club:list")
    public R list(@RequestParam Map<String, Object> params){
     	if(getUser().getBusinessId()>0) {
    		params.put("businessId", getUser().getBusinessId());
    	}
        PageUtils page = clubService.queryPage(params);

        return R.put(page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("cms:club:info")
    public R info(@PathVariable("id") Long id){
		ClubEntity club = clubService.getById(id);

        return R.put(club);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("cms:club:save")
    public R save(@RequestBody ClubEntity club){
		clubService.save(club);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("cms:club:update")
    public R update(@RequestBody ClubEntity club){
		clubService.updateById(club);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete/{id}")
    @RequiresPermissions("cms:club:delete")
    public R delete(@PathVariable("id") Long id){
		clubService.removeByIds(Arrays.asList(id));

        return R.ok();
    }
    /**
     * 推荐 or 取消推荐
     */
    @RequestMapping("/tuijian")
    @RequiresPermissions("cms:club:update")
    public R tuijian(@RequestBody ClubEntity club){
        Integer recommend = club.getRecommend();
        club = clubService.getById(club.getId());
        club.setRecommend(recommend);
        clubService.updateById(club);

        return R.ok();
    }
}

